//
//  MyHeaderView.m
//  TheRoadAD
//
//  Created by baixue on 16/8/15.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "MyHeaderView.h"
#import "PersonalCell.h"
#define TOPHEIGHT 50
#define titleBtn @[@"全部",@"活动",@"改装"]


static int i;
@implementation MyHeaderView

-(id)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
               //设置header 高度
        UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0 , Screen_Width, 60 * Screen_Height/736)];
        backView.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1];
        for (i = 0; i < 3; i++) {
            
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(Screen_Width/3*i, 5, Screen_Width/3, 40);
            
            [button setTitle:titleBtn[i] forState:UIControlStateNormal];
            [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [button setBackgroundColor:[UIColor whiteColor]];
            button.titleLabel.font = [UIFont systemFontOfSize:14];
            [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
            button.tag = 125+i;
            [backView addSubview:button];
            
            if (i != 0) {
            UIView *lineH = [[UIView alloc] initWithFrame:CGRectMake(Screen_Width/3 *i, 15, 1, 15)];
            lineH.backgroundColor = [UIColor colorWithRed:0.35 green:0.85 blue:0.82 alpha:1];
            [backView addSubview:lineH];
            }
            
        }
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(30 , 45, Screen_Width/3-60, 2)];
        _line = line;
        line.backgroundColor = [UIColor colorWithRed:0.35 green:0.85 blue:0.82 alpha:1];
        
        [backView addSubview:_line];
        [self addSubview:backView];
        
        
        //添加滑动视图
        _scrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 60 * Screen_Height/736, Screen_Width, Screen_Height-64 - 60 * Screen_Height/736)];
        _scrollerView.contentSize = CGSizeMake(Screen_Width * 3, Screen_Height-64 - 60 * Screen_Height/736);
         _scrollerView.showsHorizontalScrollIndicator = NO;
        _scrollerView.pagingEnabled = YES;
        [self addSubview:_scrollerView];
        UIView *lab = [[UIView alloc] initWithFrame:CGRectMake(30 , 100, Screen_Width/3-60, 20)];

        lab.backgroundColor = [UIColor colorWithRed:0.35 green:0.85 blue:0.82 alpha:1];
        
        
        [_scrollerView addSubview:lab];
        
    }
    return self;
}

-(void)buttonClicked:(UIButton *)sender{
    
    NSInteger index = sender.tag;
    _SelectBlock(index);
    
}




@end
